package woshiheima8;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
//猜数字游戏
public class PropertiesTest {
    public static void main(String[] args) throws IOException {
        //从文件中读取数据到Propeities集合，用Load方法实现
        Properties prop = new Properties();
        FileReader fr = new FileReader("D:\\xuexi\\game.txt");
        prop.load(fr);//用FileReader读取数据到Properties集合里面
        fr.close();


        //通过Properties集合获取到玩游戏次数
        String count = prop.getProperty("count");
        int number = Integer.parseInt(count);
        //判断次数是否达到三次
        if (number>=3){
            System.out.println("游戏试玩结束，想玩请充值");
        }else {
            //玩游戏
            GuessNumber.start();
            //次数➕1，重新写回文件，用Propeities的store方法实现
            number++;
            prop.setProperty("count",String.valueOf(number));//将键count的值传给Properties
            FileWriter fw = new FileWriter("D:\\xuexi\\game.txt");
            prop.store(fw,null);//用FileWriter将Properties里面的内容写到game.txt
            fw.close();

        }
    }

}
